﻿using System;

using Microsoft.Xna.Framework;

namespace OakEngine.Camera
{
   public class Oak_Camera
    {
       private Vector2 m_CameraPosition;
       public Vector2 CameraPosition { get { return m_CameraPosition; } set {m_CameraPosition = value; } }

       private Vector2 m_Direction;
       public Vector2 Direction { get { return m_Direction; } set { m_Direction = value; } }

       private float m_fCameraSpeed;
       public float CameraSpeed { get { return m_fCameraSpeed; } set { m_fCameraSpeed = (float)Math.Max(value, 1f); } }

       private int m_nScreenWidth;

       private int m_nScreenHeight;

       private int m_nWorldWidth;

       private int m_nWorldHeight;

       public Oak_Camera(Vector2 Startposition, int screenWidth, int screenHeight, int worldWidth, int worldHeight,float cameraSpeed)
       {
           m_CameraPosition = Startposition;
           m_nScreenWidth = screenWidth;
           m_nScreenHeight = screenHeight;
           m_nWorldWidth = worldWidth;
           m_nWorldHeight = worldHeight;
           m_Direction = new Vector2();
           m_fCameraSpeed = cameraSpeed;
       }



       public void Update(GameTime gametime)
       {


           // Do input

         //  Direction.Normalize();
               m_CameraPosition += Direction * m_fCameraSpeed* (float)gametime.ElapsedGameTime.TotalSeconds;

               BoundsCheck();

       }

       public bool BoundsCheck()
       {
           bool bIsClamped = false;

           // Clamp
           if (m_CameraPosition.X < 0)
           {
               m_CameraPosition.X = 0;
               bIsClamped = true;
           }
           if (m_CameraPosition.Y < 0)
           {
               m_CameraPosition.Y = 0;
               bIsClamped = true;
           }
           //{ [ ]         *[]}    
           int maxScreenWidth = m_nWorldWidth - m_nScreenWidth;
           int maxScreenHeight = m_nWorldHeight - m_nScreenHeight;

           if (m_CameraPosition.X > maxScreenWidth)
           {
               m_CameraPosition.X = maxScreenWidth;
               bIsClamped = true;
           }
           if (m_CameraPosition.Y > maxScreenHeight)
           {
               m_CameraPosition.Y = m_nScreenHeight;
               bIsClamped = true;
           }


           return bIsClamped;
       }
    }
}
